﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ATA.OLSD.ScoringService.Entities;

namespace CPAScoringPerformanceTester.TestTask
{
    public class ScoreTaskListTask : TestTaskBase
    {
        private UserAccessTicket ticket;
        public static string TaskName = "Score Task List Test";

        public ScoreTaskListTask(UserAccessTicket ticket)
        {
            this.ticket = ticket;
        }

        public override void Setup()
        {
            base.Setup();

            if (ticket == null)
            {
                Message = ERROR_BAD_ACCOUNT;
                IsError = true;
            }
        }

        public override bool Execute()
        {
            try
            {
                Client = ServiceProxy.NewProxy();
                var items = Client.GetPersonTasks(ticket, TaskType.Scoring);
                if (items == null || items.Length <= 0)
                {
                    Message = "There is no task found";
                }
                else
                {
                    Message = string.Format("{0} task(s) found. Task ID(s): {1}", items.Length, string.Join(",", items.Select(m=>m.TaskId)));
                }
                return true;
            }
            catch (Exception ex)
            {
                Message = ex.Message;
                return false;
            }
            finally
            {
                Client.CloseConnection();
            }
        }
    }
}
